package com.bc.mcode.util;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

public class BaseController {
    protected Logger log = LogManager.getLogger(this.getClass().getName());

    public BaseController() {
    }

    protected HttpServletRequest getRequest() {
        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes();
        return attributes.getRequest();
    }

    protected HttpSession getSession() {
        return this.getRequest().getSession(true);
    }

    public void $removeSession(String key) {
        this.getSession().removeAttribute(key);
    }

    protected Object $(String key) {
        return this.getRequest().getAttribute(key);
    }

    protected void $put(String key, Object obj) {
        this.getRequest().setAttribute(key, obj);
    }

    protected Object $Session(String key) {
        return !"project_tag".equals(key) && !"127.0.0.1".equals(key) && !"ftp_id".equals(key) && !"ftp_prot".equals(key) && !"ftp_password".equals(key) && !"ftp_user".equals(key) ? this.getSession().getAttribute(key) : System.getProperty(key);
    }

    protected void $SessionPut(String key, Object obj) {
        this.getSession().setAttribute(key, obj);
    }

   /* public SysUserVO selfInfo() {
        return (SysUserVO)this.$Session("userVO");
    }

    public String selfToken() {
        return (String)this.$Session("sso_token");
    }

    public Integer selfUserId() {
        return this.selfInfo().getUserId();
    }*/
}
